resource "google_project" "agent_project" {
  project_id = "tf-test-dialogflow-%{random_suffix}"
  name = "tf-test-dialogflow-%{random_suffix}"
  org_id = "<%= ctx[:test_env_vars]['org_id'] %>"
}

resource "google_project_service" "agent_project" {
  project = google_project.agent_project.project_id
  service = "dialogflow.googleapis.com"
  disable_dependent_services = false
}

resource "google_service_account" "dialogflow_service_account" {
  account_id = "tf-test-dialogflow-%{random_suffix}"
}

resource "google_project_iam_member" "agent_create" {
  project = google_project_service.agent_project.project
  role    = "roles/dialogflow.admin"
  member  = "serviceAccount:${google_service_account.dialogflow_service_account.email}"
}

resource "google_dialogflow_agent" "basic_agent" {
  project = google_project.agent_project.project_id
  display_name = "example_agent"
  default_language_code = "en"
  time_zone = "America/New_York"
}

resource "google_dialogflow_intent" "<%= ctx[:primary_resource_id] %>" {
  project = google_project.agent_project.project_id
  depends_on = [google_dialogflow_agent.basic_agent]
  display_name = "<%= ctx[:vars]["intent_name"] %>"
  webhook_state = "WEBHOOK_STATE_ENABLED"
  priority = 1
  is_fallback = false
  ml_disabled = true
  action = "some_action"
  reset_contexts = true
  input_context_names = ["projects/${google_project.agent_project.project_id}/agent/sessions/-/contexts/some_id"]
  events = ["some_event"]
  default_response_platforms = ["FACEBOOK","SLACK"]
}